﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;

namespace mal.WP7.Framework.Controls
{
    public class TimePicker : Microsoft.Phone.Controls.TimePicker
    {
        private string _fallbackValueStringFormat;

        /// <summary>
        /// Initializes a new instance of the TimePicker control.
        /// </summary>
        public TimePicker()
        {
            DefaultStyleKey = typeof(TimePicker);
            Value = DateTime.Now;
        }

        /// <summary>
        /// Gets the fallback value for the ValueStringFormat property.
        /// </summary>
        protected override string ValueStringFormatFallback
        {
            get
            {
                if (null == _fallbackValueStringFormat)
                {
                    // Need to convert LongTimePattern into ShortTimePattern to work around a platform bug
                    // such that only LongTimePattern respects the "24-hour clock" override setting.
                    // This technique is not perfect, but works for all the initially-supported languages.
                    string pattern = CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern.Replace(" tt", "");
                    _fallbackValueStringFormat = "{0:" + pattern + "}";
                }
                return _fallbackValueStringFormat;
            }
        }
    }
}
